package com.example.origin.finance.trade.dto;

import com.example.origin.finance.utils.CalcUtil;
import lombok.Data;

import java.util.Date;

@Data
public class TradeRecord {
    private Date buyTime;
    private Date sellTime;

    private Double buyPrice = 0d;
    private Double sellPrice = 0d;

    private Long buyVolume = 0L;
    private Long sellVolume = 0L;

    private Double buyTotalPrice = 0d;
    private Double sellTotalPrice = 0d;

    private Double profit = 0d;
    private Double profitRate = 0d;

    private String code;

    public boolean isSold() {
        return getSellTime() != null;
    }
    public boolean isBought() {
        return !isSold();
    }


    public void recordBuy(String code, Date date, Double price, Long volume) {
        setBuyPrice(price);
        setBuyVolume(volume);
        setBuyTime(date);
        setCode(code);
        setBuyTotalPrice(CalcUtil.doubleMultiply(getBuyPrice(), getBuyVolume()));
    }

    public void recordSell(Date date, Double price, Long volume) {
        setSellPrice(price);
        setSellVolume(volume);
        setSellTime(date);
        setSellTotalPrice(CalcUtil.doubleMultiply(getSellPrice(), getSellVolume()));
        setProfit(getSellTotalPrice() - getBuyTotalPrice());
        setProfitRate(CalcUtil.doubleDivide(getProfit(),getBuyTotalPrice()));
    }


}